package chapter02.two;

import java.util.Observable;
import java.util.Observer;

import chapter02.one.service.DisplayElement;

public class CurrentConditionsDisplay implements Observer, DisplayElement {

	private float temperature;
	private float humidity;

	private Observable observable;

	public CurrentConditionsDisplay(Observable observable) {
		this.observable = observable;
		this.observable.addObserver(this);
	}

	@Override
	public void display() {
		System.out.println("Current conditions: " + temperature + "F defress and " + humidity + "% humidity");
	}

	@Override
	public void update(Observable o, Object arg) {
		if (o instanceof WeatherData) {
			WeatherData data = (WeatherData) o;
			this.temperature = data.getTemperature();
			this.humidity = data.getHumidity();
			display();
		}
	}

}
